package com.diet.web.controller.diet;

import com.diet.common.annotation.Log;
import com.diet.common.core.controller.BaseController;
import com.diet.common.core.domain.AjaxResult;
import com.diet.common.core.page.TableDataInfo;
import com.diet.common.enums.BusinessType;
import com.diet.common.utils.DateUtils;
import com.diet.system.domain.Feedback;
import com.diet.system.service.IFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户反馈Controller
 */
@RestController
@RequestMapping("/diet/feedback")
public class FeedbackController extends BaseController
{
    @Autowired
    private IFeedbackService feedbackService;

    /**
     * 查询用户反馈列表
     */
    @PreAuthorize("@ss.hasPermi('diet:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(Feedback feedback)
    {
        startPage();
        List<Feedback> list = feedbackService.selectFeedbackList(feedback);
        return getDataTable(list);
    }

    /**
     * 获取用户反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('diet:feedback:query')")
    @GetMapping(value = "/{feedbackId}")
    public AjaxResult getInfo(@PathVariable("feedbackId") Long feedbackId)
    {
        return AjaxResult.success(feedbackService.selectFeedbackByFeedbackId(feedbackId));
    }

    /**
     * 新增用户反馈
     */
    @PreAuthorize("@ss.hasPermi('diet:feedback:add')")
    @Log(title = "用户反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Feedback feedback)
    {
        return toAjax(feedbackService.insertFeedback(feedback));
    }

    /**
     * 处理用户反馈
     */
    @PreAuthorize("@ss.hasPermi('diet:feedback:handle')")
    @Log(title = "用户反馈", businessType = BusinessType.UPDATE)
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody Feedback feedback)
    {
        feedback.setHandleTime(DateUtils.getNowDate());
        return toAjax(feedbackService.updateFeedback(feedback));
    }

    /**
     * 删除用户反馈
     */
    @PreAuthorize("@ss.hasPermi('diet:feedback:remove')")
    @Log(title = "用户反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{feedbackIds}")
    public AjaxResult remove(@PathVariable Long[] feedbackIds)
    {
        return toAjax(feedbackService.deleteFeedbackByFeedbackIds(feedbackIds));
    }
}